<?php

class	iniFile
{
	private $_filename;
	private $_settings;
	private $_rules = array();

	function __construct($filename)
	{
		$this->_filename = $filename;
	}
	/**
	*
	* @check if the file exist
	*
	* @access private
	*
	* @return bool
	*
	*/
	private function ini_exist()
	{
		if (is_readable($this->_filename) == false) {
			throw new Exception("File $this->_filename doesn't exist !");
		}
		return true;
	}

	/**
	*
	* @get the content of the ini file
	*
	* @access private
	*
	* @return void
	*
	*/
	private function getRulesFromFile()
	{
		$this->_settings = parse_ini_file($this->_filename, false);
	}
	
	/**
	*
	* @check if the rules exist
	*
	* @param $rule
	*
	* @access private
	*
	* @return bool
	*
	*/
	private function ruleExist($rule = array())
	{
		foreach($rule as $ruletofind) {
			foreach($this->_settings as $key => $value) {
				if ($key == $ruletofind) {
					$found = true;
				}
			}
			if ($found == false) {
				throw new Exception("Rule $ruletofind in $this->_filename is not found !");
			}
			$found = false;
		}
	}
	
	/**
	*
	* @get rules
	*
	* @param $rule = array
	*
	* @access public
	*
	* @return array
	*
	*/
	public function getRule($rule = array())
	{
		$this->ini_exist();
		$this->getRulesFromFile();
		$this->ruleExist($rule);
		foreach($rule as $ruletofind) {
			foreach($this->_settings as $key => $value) {
				if ($key == $ruletofind) {
					$this->_rules[$key] = $value;
				}
			}
		}
		return $this->_rules;
	}
	
}

?>